﻿@using Stamp_For_Africa_Version_2.Helpers
@model Stamp_For_Africa_Version_2.Models.Stamp
@{
	ViewBag.Title = "Create a new stamp";
}
<div style="padding: 20px 0px 10px 0px"></div>

<script src="@Url.Content("/uploadify/swfobject.js")" type="text/javascript"></script>
<script src="@Url.Content("/uploadify/jquery.uploadify.v2.1.4.min.js")" type="text/javascript"></script>
<link href="@Url.Content("/uploadify/uploadify.css")" rel="stylesheet" type="text/css" />

<script type="text/javascript">

	$(function () {
		$(".navbutton1").button({

		});
	});


	$(function () {

		// Uploadify File Upload System
		// SessionSync data is sent in scriptData for security reasons, see UploadifySessionSync() in global.asax

		var UploadifyAuthCookie = '@(Request.Cookies[FormsAuthentication.FormsCookieName] == null ? "" : Request.Cookies[FormsAuthentication.FormsCookieName].Value)';
		var UploadifySessionId = '@Session.SessionID';

		$("#fuFileUploader").uploadify({

			'hideButton': true,       // We use a trick below to overlay a fake html upload button with this hidden flash button                         
			'wmode': 'transparent',
			'uploader': '@Url.Content("/uploadify/uploadify.swf")',
			'cancelImg': '@Url.Content("/uploadify/cancel.png")',
			'buttonText': 'Upload File',
			'script': '@Url.Action("FileUpload", "Stamps")',
			'multi': true,
			'auto': true,
			'scriptData': { RequireUploadifySessionSync: true, SecurityToken: UploadifyAuthCookie, SessionId: UploadifySessionId },
			'onComplete': function (event, ID, fileObj, response, data) {
				response = $.parseJSON(response);
				if (response.Status == 'OK') {

					$("#UploadedFileName").val(response.returnFile);
					$("#NonRootedUploadedFileName").val(response.serverPath);
					$("#StampImage").attr("src", response.serverPath);
					// Put your own handler code here instead of the following...
					$("#dialogUploadStamp").dialog("close");
				}
			},
			'onError': function (event, queueID, fileObj, errorObj) {
				alert("Error!!! Type: [" + errorObj.type + "] Info [" + errorObj.info + "]");
			}
		});
	});

	$(function () {

		// Uploadify File Upload System
		// SessionSync data is sent in scriptData for security reasons, see UploadifySessionSync() in global.asax

		var UploadifyAuthCookie = '@(Request.Cookies[FormsAuthentication.FormsCookieName] == null ? "" : Request.Cookies[FormsAuthentication.FormsCookieName].Value)';
		var UploadifySessionId = '@Session.SessionID';

		$("#fileUploaderControlBlock").uploadify({

			'hideButton': true,       // We use a trick below to overlay a fake html upload button with this hidden flash button                         
			'wmode': 'transparent',
			'uploader': '@Url.Content("/uploadify/uploadify.swf")',
			'cancelImg': '@Url.Content("/uploadify/cancel.png")',
			'buttonText': 'Upload File',
			'script': '@Url.Action("FileUpload", "Stamps")',
			'multi': true,
			'auto': true,
			'scriptData': { RequireUploadifySessionSync: true, SecurityToken: UploadifyAuthCookie, SessionId: UploadifySessionId },
			'onComplete': function (event, ID, fileObj, response, data) {
				response = $.parseJSON(response);
				if (response.Status == 'OK') {

					$("#UploadedControlBlockFileName").val(response.returnFile);
					$("#NonRootedUploadedControlBlockFileName").val(response.serverPath);
					$("#ControlBlockImage").attr("src", response.serverPath);
					// Put your own handler code here instead of the following...
					$("#dialogUploadControlBlock").dialog("close");
				}
			},
			'onError': function (event, queueID, fileObj, errorObj) {
				alert("Error!!! Type: [" + errorObj.type + "] Info [" + errorObj.info + "]");
			}
		});
	});


  $(function () {

    // Uploadify File Upload System
    // SessionSync data is sent in scriptData for security reasons, see UploadifySessionSync() in global.asax

    var UploadifyAuthCookie = '@(Request.Cookies[FormsAuthentication.FormsCookieName] == null ? "" : Request.Cookies[FormsAuthentication.FormsCookieName].Value)';
    var UploadifySessionId = '@Session.SessionID';

    $("#fileUploaderMinatureSheet").uploadify({

      'hideButton': true,       // We use a trick below to overlay a fake html upload button with this hidden flash button                         
      'wmode': 'transparent',
      'uploader': '@Url.Content("/uploadify/uploadify.swf")',
      'cancelImg': '@Url.Content("/uploadify/cancel.png")',
      'buttonText': 'Upload File',
      'script': '@Url.Action("FileUpload", "Stamps")',
      'multi': true,
      'auto': true,
      'scriptData': { RequireUploadifySessionSync: true, SecurityToken: UploadifyAuthCookie, SessionId: UploadifySessionId },
      'onComplete': function (event, ID, fileObj, response, data) {
        response = $.parseJSON(response);
        if (response.Status == 'OK') {

          $("#UploadedMinatureSheetFileName").val(response.returnFile);
          $("#NonRootedUploadedMinatureSheetFileName").val(response.serverPath);
          $("#MinatureSheetImage").attr("src", response.serverPath);
          // Put your own handler code here instead of the following...
          $("#dialogUploadMinatureSheet").dialog("close");
        }
      },
      'onError': function (event, queueID, fileObj, errorObj) {
        alert("Error!!! Type: [" + errorObj.type + "] Info [" + errorObj.info + "]");
      }
    });
  });		
		
	
 </script>


<script type="text/javascript">

	function showDialog() {
		$("#dialogUploadStamp").dialog();
		return false;
	}
</script>

<script type="text/javascript">

	function showControlblockDialog() {
		$("#dialogUploadControlBlock").dialog();
		return false;
	}
</script>

<script type="text/javascript">

  function showMinatureSheetDialog() {
    $("#dialogUploadMinatureSheet").dialog();
    return false;
  }
</script>

@*<script type="text/javascript">
	$(document).ready(function () {
		$('.date').datepicker({ dateFormat: "dd/mm/yy" });
	});
</script>*@

@*
  -----------------------------------------------------------------------
  Upload Stamp dialog
  -----------------------------------------------------------------------
*@
<div style="display: none;" id="dialogUploadStamp" title="Upload Stamp">

		<div style="position: relative;">
        
        <input type="button" id="btnUpload" value="Upload File" />

        <div style="position: absolute; top: 4px; left: 3px;">
            <input id="fuFileUploader" name="file_upload" type="file" />
        </div>
    </div>

</div>

<div style="display: none;" id="dialogUploadControlBlock" title="Upload control block">

		<div style="position: relative;">
        
        <input type="button" id="btnUploadConrolBlock" value="Upload Control block" />

        <div style="position: absolute; top: 4px; left: 3px;">
            <input id="fileUploaderControlBlock" name="file_upload" type="file" />
        </div>
    </div>

</div>

<div style="display: none;" id="dialogUploadMinatureSheet" title="Upload minature sheet">

		<div style="position: relative;">
        
        <input type="button" id="btnUploadMinatureSheet" value="Upload Minature Sheet" />

        <div style="position: absolute; top: 4px; left: 3px;">
            <input id="fileUploaderMinatureSheet" name="file_upload" type="file" />
        </div>
    </div>

</div>

@*
  -----------------------------------------------------------------------
  Create new country dialog
  -----------------------------------------------------------------------
*@

<script type="text/javascript">

  function showCountryDialog() {
    $("#dialogCreateNewCountry").dialog();
    return false;
   }
  
   function onCreateCountry() 
	 {
	 		var countryName = $("#CountryName").val();

	 		$.ajax(
			{
				type: 'POST',
				url: '/Stamps/CreateCountry',
				data: { countryName: countryName },
				dataType: "json",

				success: function (data, response) {					
					var returnCountryName = data.CountryName;
					var returnCountryId = data.CountryId;
					$("#CountryId").append($('<option>', { value: returnCountryId }).text(returnCountryName)); 					
					$("#dialogCreateNewCountry").dialog("close");

				}
			});

	 		
			return false;
		}
</script>

<div style="display: none;" id="dialogCreateNewCountry" title="Create country">  
		<div style="position: relative;">
        
        @Html.TextBox("CountryName")<br/>   
				<a href="" onclick="return onCreateCountry()">Create country</a>
    </div>    
</div>

@*
	--------------------------------------------------------------------
	Create new artist dialog
	--------------------------------------------------------------------
*@

@* Script *@
<script type="text/javascript">

	function showArtistDialog() {		
		$("#dialogCreateNewArtist").dialog( {width: 400 });
		return false;
	}

	function onCreateArtist() {
		var artistName = $("#ArtistName").val();
		var artistSurname = $("#ArtistSurname").val();

		$.ajax(
			{
				type: 'POST',
				url: '/Stamps/CreateArtist',
				data: { name: artistName, surname: artistSurname },
				dataType: "json",

				success: function (data, response) {

					var returnArtistName = data.artistName;
					var returnArtistId = data.artistId;

					$("#ArtistId").append($('<option>', { value: returnArtistId }).text(returnArtistName)); 					
					$("#dialogCreateNewArtist").dialog("close");

				}
			});

		return false;
	}
</script>

@* Dialog *@
<div style="display: none;" id="dialogCreateNewArtist" title="Create artist">  
		<div style="position: relative;">
        <table>
					<tr>
						<td>
							@Html.Label("Name:") 
						</td>
						<td>
							@Html.TextBox("ArtistName")<br/>
						</td>
					</tr>
					<tr>
						<td>
							@Html.Label("Surname:") 
						</td>
						<td>
							@Html.TextBox("ArtistSurname")<br/>
						</td>
					</tr>
				</table>
				<a href="" onclick="return onCreateArtist()">Create artist</a>
    </div>    
</div>

@*
	--------------------------------------------------------------------
	Create new currency dialog
	--------------------------------------------------------------------
*@

@* Script *@
<script type="text/javascript">

	function showCurrencyDialog() {
		$("#dialogCreateNewCurrency").dialog({ width: 400 });
		return false;
	}

	function onCreateCurrency() {
		var displayName = $("#CurrenyDisplayName").val();
		var symbol = $("#CurrencySymbol").val();

		$.ajax(
			{
				type: 'POST',
				url: '/Stamps/CreateCurrency',
				data: { displayName: displayName, symbol: symbol },
				dataType: "json",

				success: function (data, response) {


					var returnCurrencyName = data.currencyName;
					var returnCurrencyId = data.currencyId;

					$("#CurrencyId").append($('<option>', { value: returnCurrencyId }).text(returnCurrencyName)); 					
										
					$("#dialogCreateNewCurrency").dialog("close");

				}
			});

		return false;
	}
</script>

@* Dialog *@
<div style="display: none;" id="dialogCreateNewCurrency" title="Create currency">  
		<div style="position: relative;">
        <table>
					<tr>
						<td>
							@Html.Label("Display name:") 
						</td>
						<td>
							@Html.TextBox("CurrenyDisplayName")<br/>
						</td>
					</tr>
					<tr>
						<td>
							@Html.Label("Symobol:") 
						</td>
						<td>
							@Html.TextBox("CurrencySymbol")<br/>
						</td>
					</tr>
				</table>
				<a href="" onclick="return onCreateCurrency()">Create currency</a>
    </div>    
</div>

@*
	--------------------------------------------------------------------
	Create new Colour dialog
	--------------------------------------------------------------------
*@

@* Script *@
<script type="text/javascript">

	function showColourDialog() {
		$("#dialogCreateNewColour").dialog({ width: 400 });
		return false;
	}

	function onCreateColour() {
		var displayName = $("#ColourDisplayName").val();
		
		$.ajax(
			{
				type: 'POST',
				url: '/Stamps/CreateColour',
				data: { colourName: displayName },
				dataType: "json",

				success: function (data, response) {

					alert(data.Result);
					$("#dialogCreateNewColour").dialog("close");

				}
			});

		return false;
	}
</script>

@* Dialog *@
<div style="display: none;" id="dialogCreateNewColour" title="Create colour">  
		<div style="position: relative;">
        <table>
					<tr>
						<td>
							@Html.Label("Display name:") 
						</td>
						<td>
							@Html.TextBox("ColourDisplayName")<br/>
						</td>
					</tr>
				</table>
				<a href="" onclick="return onCreateColour()">Create colour</a>
    </div>    
</div>

@*
	--------------------------------------------------------------------
	Create new Category Functionality
	--------------------------------------------------------------------
*@

@* Script *@
<script type="text/javascript">

	function showCategoryDialog() {
		$("#dialogCreateNewCategory").dialog({ width: 400 });
		return false;
	}

	function onCreateCategory() {
		var name = $("#CategoryName").val();

		$.ajax(
			{
				type: 'POST',
				url: '/Stamps/CreateCategory',
				data: { categoryName: name },
				dataType: "json",

				success: function (data, response) {


					var returnCategoryName = data.CategoryName;
					var returnCategoryId = data.CategoryId;

					$("#CategoryId").append($('<option>', { value: returnCategoryId }).text(returnCategoryName)); 					
					
					$("#dialogCreateNewCategory").dialog("close");

				}
			});

		return false;
	}
</script>


@* Dialog *@
<div style="display: none;" id="dialogCreateNewCategory" title="Create colour">  
		<div style="position: relative;">
        <table>
					<tr>
						<td>
							@Html.Label("Display name:") 
						</td>
						<td>
							@Html.TextBox("CategoryName")<br/>
						</td>
					</tr>
				</table>
				<a href="" onclick="return onCreateCategory()">Create category</a>
    </div>    
</div>



@* 
	-------------------------------------------------------------------
	Main form
	-------------------------------------------------------------------
*@
@using (Html.BeginForm())
{
	@Html.ValidationSummary(true)
	@* -- HIDDEN FIELDS -- *@
	@Html.HiddenFor(model => model.UploadedFileName)
	@Html.HiddenFor(model => model.NonRootedUploadedFileName)	
	@Html.HiddenFor(model => model.UploadedControlBlockFileName)
	@Html.HiddenFor(model => model.NonRootedUploadedControlBlockFileName)
	
			
		<fieldset class="roundedpanel">
		<legend>Images</legend>	
		
			@* -- STAMP IMAGE -- *@	
			<div>
				<a class="navbutton1" href="" onclick="return showDialog()">Select the Stamp Image</a>
			</div>
			<div>
				<img id="StampImage" src=@Model.NonRootedUploadedFileName alt="" />
			</div>

			@* -- CONTROL BLOCK IMAGE -- *@	
			<div>
				<a class="navbutton1" href="" onclick="return showControlblockDialog()">Select the Controlblock Image</a>
			</div> 
			<div>
				<img id ="ControlBlockImage" src=@Model.NonRootedUploadedControlBlockFileName alt =""/>
			</div>
		</fieldset>

		<fieldset class="roundedpanel">
		<legend>Details</legend>
		
			@* -- Display name -- *@
			<h2>Display name</h2>
			<div class="editor-field">
				@Html.EditorFor(model => model.DisplayName)
				@Html.ValidationMessageFor(model => model.DisplayName)
			</div>

			@* -- Short description -- *@
			<h2>Short description</h2>
			<p>*Please note: this is the short description. For a full description, use the "description" edit area when editing this newly created stamp</p>
			<div class="editor-field">
				@Html.EditorFor(model => model.ShortDescription)
			</div>

			@* -- Country -- *@
			<h2>Country</h2>
			<div class="editor-field">
				@Html.DropDownListFor(model => model.CountryId, ListHelpers.Countries)

				<div class="navbutton1">
					<a href="" onclick="return showCountryDialog()">Create a new country</a>
				</div>
				@Html.ValidationMessageFor(model => model.CountryId)
			</div>

			@* -- Face Value -- *@
			<h2>Face Value</h2>
			<div class="editor-field">
				@Html.EditorFor(model => model.FaceValue)
				@Html.ValidationMessageFor(model => model.FaceValue)
			</div>

			@* -- Value: Mint Never Hinged (**) --*@
			<h2>Value: Mint Never Hinged (**)</h2>
			<div class="editor-field">
				@Html.EditorFor(model => model.ValueMintNeverHinged)
				@Html.ValidationMessageFor(model => model.ValueMintNeverHinged)
			</div>

			@* -- Value: Mint Hinged (*) --*@
			<h2>Value: Mint Hinged (*)</h2>
			<div class="editor-field">
				@Html.EditorFor(model => model.ValueMintHinged)
				@Html.ValidationMessageFor(model => model.ValueMintHinged)
			</div>

			@* -- Value: Used (u) -- *@
			<h2>Value: Used (u)</h2>
			<div class="editor-field">
				@Html.EditorFor(model => model.ValueUsed)
				@Html.ValidationMessageFor(model => model.ValueUsed)
			</div>

			@* -- Currency -- *@
			<h2>Currency</h2>
			<div class="editor-field">
				@Html.DropDownListFor(model => model.CurrencyId, Model.Currencies)
				<div class="navbutton1">
					<a href="" onclick="return showCurrencyDialog()">Create a new currency</a>
				</div>
				@Html.ValidationMessageFor(model => model.CurrencyId)
			</div>

			@* -- Category -- *@
			<h2> Category</h2>
			<div class="editor-field">
				@Html.DropDownListFor(model => model.CategoryId, ListHelpers.Categories)
				<div class="navbutton1">
					<a href="" onclick="return showCategoryDialog()">Create a new category</a>
				</div>
				@Html.ValidationMessageFor(model => model.CategoryId)
			</div>

			@* -- Sub-Category -- *@
			<h2>Sub-Category</h2>
			<div class="editor-field">
				@Html.EditorFor(model => model.SubCategory)
				@Html.ValidationMessageFor(model => model.SubCategory)
			</div>

			@* -- From Date -- *@
			<h2>From date (Year only)</h2>
			<div class="editor-field">
				@Html.TextBoxFor(model => model.FromDate)
				@Html.ValidationMessageFor(model => model.FromDate)
			</div>

			@* -- To Date -- *@
			<h2>To date (Year only)</h2>
			<div class="editor-field">
				@Html.TextBoxFor(model => model.ToDate)
				@Html.ValidationMessageFor(model => model.ToDate)
			</div>

			@* -- Artist -- *@
			<h2>Artist</h2>
			<div class="editor-field">
				@Html.DropDownListFor(model => model.ArtistId, ListHelpers.Artists)
				<div class="navbutton1">
					<a href="" onclick="return showArtistDialog()">Create a new artist</a>
				</div>
				@Html.ValidationMessageFor(model => model.ArtistId)
			</div>

			@* -- Search Tags 1 -- *@
			<h2>Search Tags 1</h2>
			<div class="editor-field">
				@Html.EditorFor(model => model.SearchTags1)
				@Html.ValidationMessageFor(model => model.SearchTags1)
			</div>

			@* -- Additional Search Tags 1 -- *@
			<h2>Additional search tags</h2>
			<div class="editor-field">
				@Html.EditorFor(model => model.SearchTags2)
				@Html.ValidationMessageFor(model => model.SearchTags2)
			</div>

			@* -- Series -- *@
			<h2>Series</h2>
			<div class="editor-field">
				 @Html.DropDownListFor(model => model.SeriesId, ListHelpers.Series, "-- SELECT ONE --")
			</div>

			@* -- Issue Type -- *@
			<h2>Issue Type</h2>
			<div class="editor-field">
				@Html.DropDownListFor(model => model.TypeId, ListHelpers.IssueTypes)
			</div>

			@* -- Date Issued -- *@
			<h2>Exact date of issue</h2>
			<div class="editor-field">
				@Html.EditorFor(model => model.DateIssued)
				@Html.ValidationMessageFor(model => model.DateIssued)
			</div>

			@* -- Catalogue -- *@
			<p></p>
			<fieldset class="roundedpanel">
			<legend>Initial catalogue assignment</legend>
				<h2>Catalogue</h2>
				<p>* Please note that you can assign more catalogues to this stamp in stamp edit mode</p>
				<div class="editor-field">
					 @Html.DropDownListFor(model => model.CatalogueId, ListHelpers.Catalogues, "-- SELECT ONE --")
				</div>

				<h2>Catalogue number</h2>
				<div class="editor-field">
					@Html.EditorFor(model => model.CatalogueNumber)
					@Html.ValidationMessageFor(model => model.CatalogueNumber)
				</div>
			</fieldset>


		</fieldset>

		<p>
			<input class="navbutton1" type="submit" value="Create" />
		</p>
	
}
<p></p>
<div class="navbutton1">
	@Html.ActionLink("Back to List", "Index")
</div>
